<template>
  <div class="siteList">
    <filterPanel filterName="SSiteListFilter" filterTitle="合作站点查询" :filterList="filterData"
                 @filterChange="filterChange"></filterPanel>
    <tablePanel tableName="SSiteListTable" :tableLoading="loading" tableTitle="合作站点列表" :tableList="tableList"
                :tableData="tableData" :total="total" :currentPage="form.page_start" :pageSize="form.page_size"
                @sizeChange="sizeChange" @pageChange="pageChange" @tableClick="tableClick">
    </tablePanel>
  </div>
</template>

<script>
	export default {
		name: "SSiteList",
		props: {},
		data() {
			return {
				filterData: [
					{
						title: '合作站点名称',
						name: 'company_name',
						type: 'input',
						value: '',
            maxLength:'50',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						name: 'legal_person',
						type: 'input',
						value: '',
						maxLength:'50',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						name: 'legal_phone',
						type: 'input',
						value: '',
						maxLength:'11',
						isShow: true,
						isSelected: true
					},
					{
						title: '负责人',
						name: 'control_man',
						type: 'input',
						value: '',
						maxLength:'20',
						isShow: true,
						isSelected: true
					},
					{
						title: '负责人联系方式',
						name: 'control_phone',
						type: 'input',
						value: '',
						maxLength:'11',
						isShow: true,
						isSelected: true
					},
					{
						title: '入驻时间',
						name: 'time',
						type: 'date',
						value: [],
						isShow: true,
						isSelected: true
					}
				],
				form: {
					company_name: "",
					legal_person: "",
					legal_phone: "",
					organization_code: "",
					control_man: "",
					control_phone: "",
					page_start: 1,
					page_size: 10
				},
				tableData: [],
				tableList: [
					{
						title: '合作站点名称',
						width: 180,
						name: 'company_name',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人姓名',
						width: 180,
						name: 'legal_person',
						isShow: true,
						isSelected: true
					},
					{
						title: '法人联系方式',
						width: 180,
						name: 'legal_phone',
						isShow: true,
						isSelected: true
					},
					{
						title: '统一社会信用代码',
						width: 180,
						name: 'organization_code',
						isShow: true,
						isSelected: true
					},
					{
						title: '负责人',
						width: 180,
						name: 'control_man',
						isShow: true,
						isSelected: true
					},
					{
						title: '联系方式',
						width: 180,
						name: 'control_phone',
						isShow: true,
						isSelected: true
					},
					{
						title: '入驻时间',
						width: 180,
						name: 'create_time_cn',
						isShow: true,
						isSelected: true
					},
					{
						title: '操作',
						width: 100,
						name: 'handler',
						fixed: 'right',
						btns: [
							{
								type: 'detail',
								name: '查看'
							},
						],
						isSelected: true
					}
				],
				total: 0,
				loading: false
			};
		},
		computed: {
			postData() {
				let data = {
					...this.form,
					pagination: {
						page_start: this.form.page_start,
						page_size: this.form.page_size
					}
				};
				if (this.form.time && this.form.time.length > 0) {
					data.start_create_time = this.form.time[0] / 1000;
					data.end_create_time = this.form.time[1] / 1000;
				}
				delete data.time;
				return data;
			},
    },
		watch: {},
		components: {},
		methods: {
			sizeChange(val) {
				this.form.page_size = val;
				this.getData()
			},
			pageChange(val) {
				this.form.page_start = val;
				this.getData()
			},
			filterChange(data) {
				this.form = {...this.form, ...data};
				this.getData();
			},
			getData() {
				this.loading = true;
				this.$axios.post(this.$api.companyCooperList, this.postData).then(res => {
					let {code, msg, data} = res;
					this.loading = false;
					if (code == 200) {
						this.tableData = data.list.filter(item => {
							item.detail = true;
							return item;
						});
						this.download_url = data.download_url;

						this.total = data.pagination.total_count || 0;
					} else {
						this.total = 0;
						this.tableData = [];
					}
				}).catch(ret => {
					this.loading = false;
					this.$message.error(ret.msg || "服务繁忙，请稍后再试");
				});
			},
			tableClick(data, type) {
				this.$toRoutePath({
					path: "/sorting/siteList/detail",
					edit: true,
					query: {
						type: type,
						cooperid: data.cooperid
					}
				});
			},
		},
		mounted() {
			this.getData();
		},
		created() {
		}
	}
</script>

<style scoped lang="less" src="@/style/sorting/cooperativeSite/siteList/index.less">

</style>
